﻿using Modules.System.Menu;
using Modules.System.Role;
using PmSoft;
using PmSoft.Entity;

namespace Modules.System.User;

public static partial class SysUserExtensions
{
    public static bool IsSuperAdministrator(this SysUser user)
    {
        return !user.DeptId.HasValue || user.DeptId == 0;
    }

    public static bool IsSuperAdministrator(this IDeptUser user)
    {
        return !user.DeptId.HasValue || user.DeptId == 0;
    }

    public static IEnumerable<SysMenu> GetMenus(this SysUser user)
    {
        var menuService = ServiceAccessor.GetService<MenuService>();
        return menuService.GetUserMenus(user.UserId);
    }

    public static IEnumerable<SysRole> GetRoles(this SysUser user)
    {
        var roleService = ServiceAccessor.GetService<RoleService>();
        return roleService.GetRolesByUserId(user.UserId);
    }

    /// <summary>
    /// 判断是否是银行人员
    /// </summary>
    /// <param name="user"></param>
    /// <returns></returns>
    public static bool IsBankAdministrator(this IDeptUser user)
    {
        return user.IndustryType== 行业主管部门.银行;
    }

    /// <summary>
    /// 判断是否是人社人员
    /// </summary>
    /// <param name="user"></param>
    /// <returns></returns>
    public static bool IsRSAdministrator(this IDeptUser user)
    {
        return user.IndustryType == 行业主管部门.人社;
    }
}